﻿using Hx.ADSyncPlatform.ActiveDirectory.Attributes;
using System;
using System.Collections.Generic;

namespace Hx.ADSyncPlatform.ActiveDirectory.Model
{
    /// <summary>
    /// 计算机
    /// </summary>
    public class Computer : DirectoryObject
    {
        private Int64 accountExpires;
        /// <summary>
        /// 过期时间
        /// </summary>
        [ReadOnlyCustom]
        public Int64 AccountExpires
        {
            get
            {
                return accountExpires;
            }
            set
            {
                accountExpires = value;
                AssignedAttributes.Add(nameof(AccountExpires));
            }
        }

        private string dNSHostName;
        /// <summary>
        /// DNSHost名称
        /// </summary>
        [IgnoreUpdate]
        public string DNSHostName
        {
            get
            {
                return dNSHostName;
            }
            set
            {
                dNSHostName = value;
                AssignedAttributes.Add(nameof(DNSHostName));
            }
        }

        private string managedBy;
        /// <summary>
        /// 管理者
        /// </summary>
        public string ManagedBy
        {
            get
            {
                return managedBy;
            }
            set
            {
                managedBy = value;
                AssignedAttributes.Add(nameof(ManagedBy));
            }
        }

        private string samAccountName;
        /// <summary>
        /// 登录名（以前版本）
        /// </summary>
        [IgnoreUpdate]
        public string SamAccountName
        {
            get
            {
                return samAccountName;
            }
            set
            {
                samAccountName = value;
                AssignedAttributes.Add(nameof(SamAccountName));
            }
        }

        private string userPrincipalName;

        /// <summary>
        ///登录名（新的）
        /// </summary>
        [IgnoreUpdate]
        public string UserPrincipalName
        {
            get
            {
                return userPrincipalName;
            }
            set
            {
                userPrincipalName = value;
                AssignedAttributes.Add(nameof(UserPrincipalName));
            }
        }


        /// <summary>
        ///操作系统
        /// </summary>
        [IgnoreUpdate]
        public string OperatingSystem
        {
            get
            {
                return operatingSystem;
            }
            set
            {
                operatingSystem = value;
                AssignedAttributes.Add(nameof(OperatingSystem));
            }
        }
        private string operatingSystem;


        /// <summary>
        ///操作系统版本
        /// </summary>
        [IgnoreUpdate]
        public string OperatingSystemVersion
        {
            get
            {
                return operatingSystemVersion;
            }
            set
            {
                operatingSystemVersion = value;
                AssignedAttributes.Add(nameof(OperatingSystemVersion));
            }
        }

        /// <summary>
        /// 操作系统版本
        /// </summary>
        private string operatingSystemVersion;

        private long userAccountControl;


        [IgnoreUpdate]
        /// <summary>
        /// 用户控制
        /// </summary>
        public long UserAccountControl
        {
            get
            {
                return userAccountControl;
            }
            set
            {
                userAccountControl = value;
                AssignedAttributes.Add(nameof(UserAccountControl));
            }
        }


        /// <summary>
        /// 私人计算机 存用户名
        /// </summary>
        public string Info
        {
            get
            {
                return info;
            }
            set
            {
                info = value;
                AssignedAttributes.Add(nameof(Info));
            }
        }

        private string info;


        public string ComputerName { get => this.samAccountName?.Replace("$", "").ToLower().Replace(".", "-"); }


        public bool Enable
        {
            get
            {
                return (this.UserAccountControl & 0x0002) != 0;
            }
        }

        public List<Person> BindUsers
        {
            get; set;
        }

        public bool Binded
        {
            get; set;
        }

        public bool isOld
        {

            get; set;
        }
    }
}
